package org.example.testgis.controller;

import org.example.testgis.entity.PointTest;
import org.example.testgis.service.IPointTestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class HelloController {
    @Autowired
    private IPointTestService pointTestService;

    @GetMapping("/findAll")
    public String findAll() {
        List<PointTest> pointList = pointTestService.selectList(null);
        System.out.println(pointList);
        return pointList.toString();
    }

    @PostMapping("/insert")
    public String insert(PointTest pointTest) {
        pointTestService.insertPointTest(pointTest);
        return "done";
    }

    @GetMapping("/auto-publish")
    public ResponseEntity<Map<String, Object>> autoPublish(@RequestParam String id) {
        Map<String, Object> result = pointTestService.autoPublishLayer(Long.valueOf(id));
        if ((boolean)result.get("success")) {
            return ResponseEntity.ok(result);
        } else {
            return ResponseEntity.badRequest().body(result);
        }
    }
}
